<?php
    
	
include_once('./db.conf');
// Connects to your Database 
mysql_connect(DBHOST, DBUSER, DBPASS) or die(mysql_error()); 
mysql_select_db(DBDBNAME) or die(mysql_error()); 

if(isset($_COOKIE['AdminCookie'])){

    if (isset($_POST['remove']) && isset($_POST['customerId']))
    {
        foreach ($_POST['customerId'] as $customerId)
        {
            if (!mysql_query("DELETE FROM customers WHERE customerId = '$customerId'"))
            {
                echo error_message(sql_error());
            }
        }
    }
    

    $result  = mysql_query("SELECT customerId, firstName FROM customers GROUP BY (customerId) ASC");

    echo "<form action='{$_SERVER['PHP_SELF']}' method='POST'>\n".
         "  <table width='500' border='1' cellspacing='0' cellpadding='0'>\n".
         "      <tr align='middle'>\n".
         "          <td>ID</td>\n".
         "          <td>Customer name</td>\n".
         "          <td>Remove</td>\n".
         "          <td></td>\n".
         "      </tr>\n";

    while ($row = mysql_fetch_array($result))
    {
        echo "      <tr align='middle'>\n".
             "          <td>".$row['customerId'].             "</td>\n".
             "          <td>".$row['firstName'].           "</td>\n".
          
             " <td><input type='checkbox' name='customerId[]' value='{$row['customerId']}'>{$row['customerId']}</input></td>\n".
             "      </tr>\n";
    }
	
	echo "<h1> Administrator Area </h1>" ;
	
	echo "Select Customer(s) which you want to remove:"; 
	
    echo "      <tr>\n".
         " <td colspan='5' align='right'><input type='submit' name='remove' value='Delete' onclick=\"return confirm('Are you sure you want to delete the selected Customer(s)?');\" /></td>\n".
         "      </tr>\n".
         "  </table>\n".
         "</form>";
}
else
	die('Session Expired Please Login...');
?>
